package com.wanglv.test;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

public class SuccessActivity extends AppCompatActivity {

    SQLiteHelper sqLiteHelper;
    private ListView list;
    private ListAdapter listAdapter;
    List<User> users;
    private static final String TAG = "SuccessActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_success);
        initView();
    }

    private void initView() {
        users=new ArrayList<>();
        list = (ListView) findViewById(R.id.list);
        sqLiteHelper=new SQLiteHelper(this);
        SQLiteDatabase db = sqLiteHelper.getReadableDatabase();
        Cursor cursor = db.rawQuery("select * from user", null);
        while (cursor.moveToNext()){
            int id = cursor.getInt(0);
            String username = cursor.getString(1);
            String password = cursor.getString(2);
            String sex = cursor.getString(3);
            User user=new User(id,username,password,sex);
            users.add(user);
            Log.d(TAG, "initView: "+user);
        }
        listAdapter=new ListAdapter(users,this);
        list.setAdapter(listAdapter);
    }
}
